using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace Rotempco.Core.Web.Logic
{
    public static class WebConvertHelper
    {
        public static string ToDate(object dateString)
        {
            return DateTime.Parse(dateString.ToString()).ToString("dd-MM-yyyy");
        }

        public static string ConcatAndStripHtml(int numberOfChars, object htmlString)
        {
            string htmlStripped = StripHtml(htmlString + "");
            if (htmlStripped.Length <= numberOfChars)
                return htmlStripped;
            else
                return htmlStripped.Remove(numberOfChars) + "...";
        }

        private static string StripHtml(string htmlString)
        {
            return Regex.Replace(htmlString, @"<(.|\n)*?>", string.Empty);
        }

        internal static string ToCheckbox(object boolString)
        {
            if (boolString.ToString().ToLower() == "true")
                return "<input type=\"checkbox\" checked disabled />";
            else
                return "<input type=\"checkbox\" disabled />";
        }

        public static void ShowHideClientSide(WebControl webControl, bool show)
        {
            webControl.Style.Add("display", show ? "block" : "none");
        }
    }
}
